[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[OPTIMIZE 1]
[OPTION 1]
[BITS 32]
	EXTERN	_memman_alloc_4k
	EXTERN	_tek_getsize
	EXTERN	_tek_decomp
	EXTERN	_memman_free_4k
[FILE "file.c"]
[SECTION .text]
	GLOBAL	_file_readfat
_file_readfat:
	PUSH	EBP
	XOR	ECX,ECX
	MOV	EBP,ESP
	PUSH	EDI
	PUSH	ESI
	PUSH	EBX
	MOV	EDI,DWORD [8+EBP]
	MOV	ESI,DWORD [12+EBP]
	XOR	EBX,EBX
L6:
	MOVZX	EAX,BYTE [1+ECX+ESI*1]
	MOVZX	EDX,BYTE [ECX+ESI*1]
	SAL	EAX,8
	OR	EDX,EAX
	AND	EDX,4095
	MOV	DWORD [EDI+EBX*4],EDX
	MOV	AL,BYTE [1+ECX+ESI*1]
	MOVZX	EDX,BYTE [2+ECX+ESI*1]
	SHR	AL,4
	ADD	ECX,3
	SAL	EDX,4
	MOVZX	EAX,AL
	OR	EAX,EDX
	MOV	DWORD [4+EDI+EBX*4],EAX
	ADD	EBX,2
	CMP	EBX,2879
	JLE	L6
	POP	EBX
	POP	ESI
	POP	EDI
	POP	EBP
	RET
	GLOBAL	_file_loadfile
_file_loadfile:
	PUSH	EBP
	MOV	EBP,ESP
	PUSH	EDI
	PUSH	ESI
	PUSH	EBX
	MOV	ECX,DWORD [12+EBP]
	MOV	ESI,DWORD [8+EBP]
	MOV	EBX,DWORD [16+EBP]
L10:
	CMP	ECX,512
	JLE	L27
	XOR	EDX,EDX
L23:
	MOV	EAX,ESI
	MOV	EDI,DWORD [24+EBP]
	SAL	EAX,9
	ADD	EAX,EDX
	MOV	AL,BYTE [EAX+EDI*1]
	MOV	BYTE [EDX+EBX*1],AL
	INC	EDX
	CMP	EDX,511
	JLE	L23
	MOV	EAX,DWORD [20+EBP]
	SUB	ECX,512
	ADD	EBX,512
	MOV	ESI,DWORD [EAX+ESI*4]
	JMP	L10
L27:
	XOR	EDX,EDX
	CMP	EDX,ECX
	JGE	L9
L18:
	MOV	EAX,ESI
	MOV	EDI,DWORD [24+EBP]
	SAL	EAX,9
	ADD	EAX,EDX
	MOV	AL,BYTE [EAX+EDI*1]
	MOV	BYTE [EDX+EBX*1],AL
	INC	EDX
	CMP	EDX,ECX
	JL	L18
L9:
	POP	EBX
	POP	ESI
	POP	EDI
	POP	EBP
	RET
	GLOBAL	_file_search
_file_search:
	PUSH	EBP
	XOR	ECX,ECX
	MOV	EBP,ESP
	PUSH	EDI
	PUSH	ESI
	PUSH	EBX
	SUB	ESP,20
	MOV	EBX,DWORD [8+EBP]
L33:
	MOV	BYTE [-28+EBP+ECX*1],32
	INC	ECX
	CMP	ECX,10
	JLE	L33
	XOR	ECX,ECX
	XOR	EDI,EDI
	CMP	BYTE [EBX],0
	JE	L60
L42:
	XOR	EAX,EAX
	CMP	ECX,10
	JG	L28
	MOV	DL,BYTE [EDI+EBX*1]
	CMP	DL,46
	JE	L64
L39:
	LEA	EAX,DWORD [-97+EDX]
	MOV	BYTE [-28+EBP+ECX*1],DL
	CMP	AL,25
	JA	L41
	LEA	EAX,DWORD [-32+EDX]
	MOV	BYTE [-28+EBP+ECX*1],AL
L41:
	INC	ECX
L36:
	INC	EDI
	CMP	BYTE [EDI+EBX*1],0
	JNE	L42
L60:
	XOR	EDI,EDI
	CMP	EDI,DWORD [16+EBP]
	JGE	L44
	MOV	ESI,DWORD [12+EBP]
	MOV	DWORD [-32+EBP],0
L56:
	MOV	EAX,DWORD [12+EBP]
	CMP	BYTE [EAX],0
	JE	L44
	TEST	BYTE [11+ESI],24
	JNE	L54
	MOV	EBX,EAX
	XOR	ECX,ECX
	ADD	EBX,DWORD [-32+EBP]
L55:
	MOVZX	EDX,BYTE [EBX]
	MOVSX	EAX,BYTE [-28+EBP+ECX*1]
	CMP	EDX,EAX
	JNE	L54
	INC	ECX
	INC	EBX
	MOV	EAX,ESI
	CMP	ECX,10
	JLE	L55
L28:
	ADD	ESP,20
	POP	EBX
	POP	ESI
	POP	EDI
	POP	EBP
	RET
L54:
	INC	EDI
	ADD	ESI,32
	ADD	DWORD [-32+EBP],32
	CMP	EDI,DWORD [16+EBP]
	JL	L56
L44:
	XOR	EAX,EAX
	JMP	L28
L64:
	CMP	ECX,8
	JG	L39
	MOV	ECX,8
	JMP	L36
	GLOBAL	_file_loadfile2
_file_loadfile2:
	PUSH	EBP
	MOV	EBP,ESP
	PUSH	EDI
	PUSH	ESI
	PUSH	EBX
	PUSH	EDX
	MOV	EAX,DWORD [12+EBP]
	MOV	EAX,DWORD [EAX]
	PUSH	EAX
	MOV	DWORD [-16+EBP],EAX
	PUSH	3932160
	CALL	_memman_alloc_4k
	PUSH	1064448
	PUSH	DWORD [16+EBP]
	PUSH	EAX
	MOV	EDI,EAX
	PUSH	DWORD [-16+EBP]
	PUSH	DWORD [8+EBP]
	CALL	_file_loadfile
	ADD	ESP,28
	CMP	DWORD [-16+EBP],16
	JG	L68
L66:
	LEA	ESP,DWORD [-12+EBP]
	MOV	EAX,EDI
	POP	EBX
	POP	ESI
	POP	EDI
	POP	EBP
	RET
L68:
	PUSH	EDI
	CALL	_tek_getsize
	MOV	ESI,EAX
	POP	EAX
	TEST	ESI,ESI
	JLE	L66
	PUSH	ESI
	PUSH	3932160
	CALL	_memman_alloc_4k
	PUSH	ESI
	MOV	EBX,EAX
	PUSH	EAX
	PUSH	EDI
	CALL	_tek_decomp
	PUSH	DWORD [-16+EBP]
	PUSH	EDI
	MOV	EDI,EBX
	PUSH	3932160
	CALL	_memman_free_4k
	ADD	ESP,32
	MOV	EAX,DWORD [12+EBP]
	MOV	DWORD [EAX],ESI
	JMP	L66
